package cn.jvtc.course.management.system.dao.impl;

import cn.jvtc.course.management.system.bean.TeacherLessonClassNexusDO;
import cn.jvtc.course.management.system.exception.TeacherLessonClassNexusDaoException;
import cn.jvtc.course.management.system.utils.JdbcUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Timestamp;

/**
 * 用于操作数据库中的教师课程表与班级表的关系表
 *
 * @author GaoFeng2017
 * @date 2017-12-13 16:21:22
 **/

public class TeacherLessonClassNexusDaoImpl {
    /**
     * @description:
     * @author: GaoFeng2017
     * @date: 2017/12/13 16:23
     * @param: [teacherLessonClassNexusDO]
     * @return: boolean
     *
     */

    public boolean addTeacherLessonClassNexus(TeacherLessonClassNexusDO teacherLessonClassNexusDO) {
        Connection con = null;
        PreparedStatement st = null;
        ResultSet rs = null;

        int i = 0;
        String sql = "insert into teacher_lesson_class_nexus(gmt_create,class_id,teacher_lesson_id) values(?,?,?)";

        try{
            con = JdbcUtils.getConnection();
            st = con.prepareStatement(sql);
            st.setTimestamp(1, new Timestamp(System.currentTimeMillis()));
            st.setLong(2,teacherLessonClassNexusDO.getClassId());
            st.setLong(3,teacherLessonClassNexusDO.getTeacherLessonId());
            i = st.executeUpdate();
        } catch(Exception e) {
            throw new TeacherLessonClassNexusDaoException(e);
        } finally {
            JdbcUtils.releaseResource(con,st,rs);
        }

        if(i <= 0) {
            return false;
        }
        return true;
    }
}
